package com.feel.controller;

import com.feel.pojo.RespBean;
import com.feel.pojo.ServiceParts;
import com.feel.service.ServicePartsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author: 刘永钦
 * @Date: 2024-09-05-15:35
 * @Description:
 */
@RestController
@RequestMapping("/admin/serviceParts")
public class ServicePartsController {
    @Autowired
    private ServicePartsService servicePartsService;

    /**
     * 获得订单中适用的配件列表
     */
    @GetMapping("/{id}")
    RespBean getList(@PathVariable("id") Integer id) {
        List<ServiceParts> list = servicePartsService.getAllById(id);
        return RespBean.ok("查询成功", list);
    }

    /**
     * 获取全部配件列表
     */
    @GetMapping("/list")
    RespBean getPartsList() {
        List<ServiceParts> list = servicePartsService.getAllParts();
        return RespBean.ok("查询成功", list);
    }
    /**
     * 更新配件使用情况
     */
    @PutMapping
    RespBean updateInfo(@RequestBody Map<String, Object> map) {
        Integer id = (Integer) map.get("id");
        List<ServiceParts> parts = (List<ServiceParts>) map.get("parts");
        Boolean b = servicePartsService.updateInfo(id, parts);
        return b ? RespBean.ok("更新成功") : RespBean.error("更新失败");
    }
}
